//
//  BaoxiuVC.swift
//  Xiaozihui
//
//  Created by 校企荟 on 2017/10/18.
//  Copyright © 2017年 校企荟. All rights reserved.
//

import UIKit

class BaoxiuVC: BaseVC {

    lazy var addressView: BaoxiuAddressView = {
        let v = BaoxiuAddressView(frame:CGRect.zero)
        return v
    }()
    
    lazy var propertyView: BaoxiuPorpertyView = {
        let v = BaoxiuPorpertyView(frame:CGRect.zero)
        return v
    }()
    
    lazy var selView: BaoxiuSelView = {
        let v = BaoxiuSelView(frame:CGRect.zero)
        return v
    }()
    
    lazy var commentView: BaoxiuCommentView = {
        let v = BaoxiuCommentView(frame:CGRect.zero)
        return v
    }()
    
    lazy var pickPicView: BaoxiuPickPicView = {
        let v = BaoxiuPickPicView(frame:CGRect.zero)
        return v
    }()
    
    lazy var commitBtn: UIButton = {
        let btn = UIButton()
        btn.setAttributedTitle(NSAttributedString(string: "提  交", attributes: [NSForegroundColorAttributeName:UIColor.white,NSFontAttributeName:UIFont.boldSystemFont(ofSize: 18 * ScaleX)]), for: .normal)
        btn.backgroundColor = mainColor
        btn.layer.cornerRadius = 5
        btn.layer.masksToBounds = true
        return btn
    }()
    
    lazy var scrollView: UIScrollView = {
        let sv = UIScrollView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight))
        return sv
    }()
    
    override func setupUI() {
        
        view.addSubview(scrollView)
        
    
//
        scrollView.addSubview(addressView)
        scrollView.addSubview(propertyView)
        scrollView.addSubview(selView)
        scrollView.addSubview(commentView)
        scrollView.addSubview(pickPicView)
        scrollView.addSubview(commitBtn)
        
        addressView.snp.makeConstraints { (make) in
            make.width.equalTo(ScreenWidth)
            make.left.top.right.equalTo(scrollView)
        }
        propertyView.snp.makeConstraints { (make) in
            make.top.equalTo(addressView.snp.bottom)
            make.left.right.equalTo(addressView)
        }
        
        selView.snp.makeConstraints { (make) in
            make.top.equalTo(propertyView.snp.bottom)
            make.left.right.equalTo(addressView)
        }
        
        commentView.snp.makeConstraints { (make) in
            make.top.equalTo(selView.snp.bottom)
            make.left.right.equalTo(addressView)
        }
        
        pickPicView.snp.makeConstraints { (make) in
            make.top.equalTo(commentView.snp.bottom)
            make.left.right.equalTo(addressView)
        }
        
        commitBtn.snp.makeConstraints { (make) in
            make.top.equalTo(pickPicView.snp.bottom).offset(40)
            make.width.equalTo(150 * ScaleX)
            make.height.equalTo(40 * ScaleX)
            make.centerX.equalTo(scrollView)
            make.bottom.equalTo(scrollView).offset(40)
        }
        
        let tap1 = UITapGestureRecognizer(target: self, action: #selector(actionResignFirstResponder))
        let tap2 = UITapGestureRecognizer(target: self, action: #selector(actionResignFirstResponder))
        let tap3 = UITapGestureRecognizer(target: self, action: #selector(actionResignFirstResponder))
        
        commentView.addGestureRecognizer(tap1)
        propertyView.addGestureRecognizer(tap2)
        selView.addGestureRecognizer(tap3)
    }
    
    func actionResignFirstResponder() {
       commentView.textView.resignFirstResponder()
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
       
    }
}

extension BaoxiuVC:UIGestureRecognizerDelegate {
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }
    
}
